from django.shortcuts import render,HttpResponse
from app.models import *
import time
# Create your views here.

def index(request):
    t=time.ctime()
    return render(request,'index.html',{"time":t}) #模板传值


def article_year(request):
    return HttpResponse("2004")

def title(request):
    return render(request,'index.html')

def addbook(request):
    b=Book(name="python基础",price=99,author="yuan",pub_date="2017-12-12")
    b.save()
    return HttpResponse('添加成功')

def update(request):
    Book.objects.filter(author="yuan").update(price="300")
    return HttpResponse('修改成功')


def delete(request):
    Book.objects.filter(author="haha").delete()
    return HttpResponse('删除成功')

def select(request):
    # booklist=Book.objects.all()
    # booklist=Book.objects.all()[:1]    #取前几条
    # booklist=Book.objects.all()[::-1]    #倒着取
    return render(request,'index.html',{"booklist":booklist})


